﻿using Seggu.Services.Interfaces;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace Seggu.Desktop.Forms
{
    public partial class Bancos : Form
    {
        #region Private Members
        private IBankService bankService;
        #endregion

        #region Constructor
        public Bancos(IBankService bankService)
        {
            InitializeComponent();
            this.bankService = bankService;
            this.InitializeIndex();
        }
        #endregion

        #region Private Methods
        private void InitializeIndex()
        {
            var table = this.GetBankDataTable();
            this.bankGrid.DataSource = table;
            this.bankGrid.Columns["Id"].Visible = false;
        }

        private DataTable GetBankDataTable()
        {
            var table = new DataTable();
            table.Columns.Add("Id", typeof(string));
            table.Columns.Add("Numero", typeof(string));
            table.Columns.Add("Nombre", typeof(string));

            var banks = this.bankService.GetAll();

            foreach (var bank in banks)
            {
                var row = table.NewRow();
                row["Id"] = bank.Id;
                row["Numero"] = bank.Number;
                row["Nombre"] = bank.Name;
                table.Rows.Add(row);
            }

            return table;
        }
        #endregion

        #region Public Methods
        public void Index()
        {
            this.InitializeIndex();
        }
        #endregion

        private void btnEliminar_Click(object sender, EventArgs e)
        {
            //eliminar selected row
            string Id = bankGrid.SelectedCells[0].Value.ToString();
            bankService.Delete(Id);
            this.InitializeIndex();
        }

    }
}
